﻿Imports Infragistics.Win.UltraWinGrid

Public Class MuaHangTrongNuoc
    'state : 0 mặc định - trạng thái 1- tạo mới 2 sửa 3 - xóa
    Private state As Integer
    'load form
    Dim isLoad As Boolean = True
    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If keyData = (Keys.Control Or Keys.N) Then
            Return getTaoMoi()
        End If
        If keyData = (Keys.Control Or Keys.S) Then
            Return getLuu()
        End If
        If keyData = (Keys.Control Or Keys.E) Then
            Return getSua()
        End If
        If keyData = (Keys.Control Or Keys.D) Then
            Return Me.KetoantienmatIUltraGrid_ThongTin.getXoa()
        End If
        If keyData = (Keys.Control Or Keys.P) Then
            'Return Me.getIn()
        End If
        If keyData = (Keys.Control Or Keys.R) Then
            Return Me.KetoantienmatIUltraGrid_ThongTin.getRefresh()
        End If
        If (keyData = (Keys.Control Or Keys.Q)) Then
            Return getThoat()
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function

    Private Sub loadDuLieu()
        If isLoad Then
            Me.Cursor = Cursors.WaitCursor
            'Dim load As UltraActivityIndicator = New UltraActivityIndicator
            'load.Show()
            Me.DmkhoanmucphiTableAdapter.Fill(Me.ErpharmaDataSet.dmkhoanmucphi)
            Me.MuahangtrongnuocTableAdapter.Fill(Me.ErpharmaDataSet.muahangtrongnuoc)
            Me.Muahangtrongnuoc_thongtinthueTableAdapter.Fill(Me.ErpharmaDataSet.muahangtrongnuoc_thongtinthue)
            Me.Muahangtrongnuoc_thongtinhanghoaTableAdapter.Fill(Me.ErpharmaDataSet.muahangtrongnuoc_thongtinhanghoa)
            Me.DmnghiepvuTableAdapter.Fill(Me.ErpharmaDataSet.dmnghiepvu)
            Me.DmnhanvienTableAdapter.Fill(Me.ErpharmaDataSet.dmnhanvien)
            Me.DmphongbanTableAdapter.Fill(Me.ErpharmaDataSet.dmphongban)
            Me.DmloaitienTableAdapter.Fill(Me.ErpharmaDataSet.dmloaitien)
            Me.DmkhachhangTableAdapter.Fill(Me.ErpharmaDataSet.dmkhachhang)
            Me.DmtinhtrangphieuTableAdapter.Fill(Me.ErpharmaDataSet.dmtinhtrangphieu)
            Me.Dmtaikhoancap2TableAdapter.Fill(Me.ErpharmaDataSet.dmtaikhoancap2)
            'set giao diện
            Me.KetoantienmatIUltraGrid_ThongTin.setGiaoDien_Doi_ThongTin()
            Me.KetoantienmatIUltraGrid_DanhSach.setGiaoDienTuyBien()
            Me.DmnghiepvuIUltraDropDown.setGiaoDien_An_ColumnHeader()
            Me.DmnhanvienIUltraDropDown.setGiaoDien()
            Me.DmphongbanIUltraDropDown.setGiaoDien()
            Me.DmloaitienIUltraDropDown.setGiaoDien_An_ColumnHeader()
            Me.DmkhachhangIUltraDropDown.setGiaoDien()
            Me.DmtinhtrangphieuIUltraDropDown.setGiaoDien_An_ColumnHeader()
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setGiaoDienTuyBien()
            Me.Ketoantienmat_thongtinthueIUltraGrid.setGiaoDienTuyBien()
            Me.DmkhachhangIUltraGrid.setGiaoDienTuyBien()
            Me.DmkhachhangIUltraGrid1.setGiaoDienTuyBien()
            Me.Dmtaikhoancap2IUltraDropDown.setGiaoDien_An_ColumnHeader()
            Me.Dmtaikhoancap2IUltraDropDown1.setGiaoDien_An_ColumnHeader()
            Me.DmkhoanmucphiIUltraDropDown.setGiaoDien_An_ColumnHeader()
            'set tìm kiếm
            'Me.DmkhachhangIUltraGrid.setTimKiemTrenCotUltraGrid()
            'Me.DmkhachhangIUltraGrid1.setTimKiemTrenCotUltraGrid()
            'set doi tuong 
            'Me.DmkhachhangIUltraGrid.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.dmkhachhang, Me.DmkhachhangBindingSource, Me.DmkhachhangTableAdapter, Me.ErpharmaDataSet)
            'Me.DmkhachhangIUltraGrid1.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.dmkhachhang, Me.DmkhachhangBindingSource, Me.DmkhachhangTableAdapter, Me.ErpharmaDataSet)
            'menustrip
            Me.DmkhachhangIUltraGrid.setChoPhepMenuStrip()
            'Me.DmkhachhangIUltraGrid1.setChoPhepMenuStrip()
            'ultracomboeditor
            'Me.DmkhachhangIUltraComBoEditor.setThemUltraGrid(Me.DmkhachhangIUltraGrid)
            'Me.DmkhachhangIUltraComBoEditor1.setThemUltraGrid(Me.DmkhachhangIUltraGrid1)
            'danh sách
            Me.KetoantienmatIUltraGrid_DanhSach.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.muahangtrongnuoc, Me.MuahangtrongnuocBindingSource, Me.MuahangtrongnuocTableAdapter, Me.ErpharmaDataSet)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmnghiepvuIUltraDropDown, Me.ErpharmaDataSet.dmnghiepvu)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmnhanvienIUltraDropDown, Me.ErpharmaDataSet.dmnhanvien)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmphongbanIUltraDropDown, Me.ErpharmaDataSet.dmphongban)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmloaitienIUltraDropDown, Me.ErpharmaDataSet.dmloaitien)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmkhachhangIUltraDropDown, Me.ErpharmaDataSet.dmkhachhang)
            Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmtinhtrangphieuIUltraDropDown, Me.ErpharmaDataSet.dmtinhtrangphieu)
            Me.KetoantienmatIUltraGrid_DanhSach.setTimKiemTrenCotUltraGrid()
            KetoantienmatIUltraGrid_DanhSach.setSummaries("nguyente")
            KetoantienmatIUltraGrid_DanhSach.setSummaries("tienvnd")
            'thông tin
            Me.KetoantienmatIUltraGrid_ThongTin.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.muahangtrongnuoc, Me.MuahangtrongnuocBindingSource, Me.MuahangtrongnuocTableAdapter, Me.ErpharmaDataSet)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmnghiepvuIUltraDropDown, Me.ErpharmaDataSet.dmnghiepvu)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmnhanvienIUltraDropDown, Me.ErpharmaDataSet.dmnhanvien)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmphongbanIUltraDropDown, Me.ErpharmaDataSet.dmphongban)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmloaitienIUltraDropDown, Me.ErpharmaDataSet.dmloaitien)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmkhachhangIUltraDropDown, Me.ErpharmaDataSet.dmkhachhang)
            Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmtinhtrangphieuIUltraDropDown, Me.ErpharmaDataSet.dmtinhtrangphieu)
            ' Me.KetoantienmatIUltraGrid_ThongTin.setUltraComboEditor(Me.DmkhachhangIUltraComBoEditor)
            'gán mặc định
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("loaitien", "VND")
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("tygia", 1)
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("nguyente", 0)
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("tienvnd", 0)
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("sochungtu", "")
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("ngaylap", Today)
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("ngaylapthamchieu", Today)
            'bắt lỗi
            'set cot bat loi
            Me.KetoantienmatIUltraGrid_ThongTin.setCotBatLoi("nghiepvu")
            Me.KetoantienmatIUltraGrid_ThongTin.setCotBatLoi("donvi")
            Me.KetoantienmatIUltraGrid_ThongTin.setCotBatLoi("tinhtrang")
            'thông tin chính
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.muahangtrongnuoc_thongtinhanghoa, Me.Muahangtrongnuoc_thongtinhanghoaBindingSource, Me.Muahangtrongnuoc_thongtinhanghoaTableAdapter, Me.ErpharmaDataSet)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setThemIUltraDropDown(Me.Dmtaikhoancap2IUltraDropDown, Me.ErpharmaDataSet.dmtaikhoancap2)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setThemIUltraDropDown(Me.Dmtaikhoancap2IUltraDropDown1, Me.ErpharmaDataSet.dmtaikhoancap2)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setThemIUltraDropDown(Me.DmkhachhangIUltraDropDown, Me.ErpharmaDataSet.dmkhachhang)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setThemIUltraDropDown(Me.DmphongbanIUltraDropDown, Me.ErpharmaDataSet.dmphongban)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setUltraComboEditor(Me.DmkhachhangIUltraComBoEditor1)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setThemIUltraDropDown(Me.DmkhoanmucphiIUltraDropDown, Me.ErpharmaDataSet.dmkhoanmucphi)
            Ketoantienmat_thongtinchinhIUltraGrid.setChoPhepMenuStrip()
            'thông tin thuế 
            Me.Ketoantienmat_thongtinthueIUltraGrid.setThemIUltraDropDown(Me.DmkhachhangIUltraDropDown, Me.ErpharmaDataSet.dmkhachhang)
            'mặc định
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("dongianguyente", 0)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("dongiavnd", 0)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("thanhtiennguyente", 0)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("thanhtienvnd", 0)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setCotBatLoi("soluong")
            'summaries thông tin chính
            'thêm tổng summaries
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setSummaries("dongianguyente")
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setSummaries("dongiavnd")
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setSummaries("thanhtiennguyente")
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setSummaries("thanhtienvnd")
            'thông tin khai thuế
            Me.Ketoantienmat_thongtinthueIUltraGrid.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.muahangtrongnuoc_thongtinthue, Me.Muahangtrongnuoc_thongtinthueBindingSource, Me.Muahangtrongnuoc_thongtinthueTableAdapter, Me.ErpharmaDataSet)
            Me.Ketoantienmat_thongtinthueIUltraGrid.setChoPhepMenuStrip()
            'Me.MuahangtrongnuocBindingSource.MoveLast()
            'If KetoantienmatIUltraGrid_ThongTin.Rows.Count > 0 Then
            '    KetoantienmatIUltraGrid_ThongTin.ActiveRowScrollRegion.ScrollRowIntoView(Me.KetoantienmatIUltraGrid_ThongTin.Rows(Me.KetoantienmatIUltraGrid_ThongTin.Rows.Count - 1))
            'End If
            Me.KetoantienmatIUltraGrid_ThongTin.setMoveLast()
            'tìm kiếm
            Me.Ketoantienmat_thongtinchinhIUltraGrid_TimKiem.setGiaoDienTuyBien()
            Me.Ketoantienmat_thongtinthueIUltraGrid_TimKiem.setGiaoDienTuyBien()
            Me.Ketoantienmat_thongtinchinhIUltraGrid_TimKiem.setTimKiemTrenCotUltraGrid()
            Me.Ketoantienmat_thongtinthueIUltraGrid_TimKiem.setTimKiemTrenCotUltraGrid()
            Me.Ketoantienmat_thongtinchinhIUltraGrid_TimKiem.setGroupBy("ma")
            Me.Ketoantienmat_thongtinthueIUltraGrid_TimKiem.setGroupBy("ma")
            Ketoantienmat_thongtinthueIUltraGrid_TimKiem.setReadonly(True)
            Me.Ketoantienmat_thongtinchinhIUltraGrid_TimKiem.setReadonly(True)
            Me.Ketoantienmat_thongtinchinhIUltraGrid.setTimKiemTrenCotUltraGrid()
            'thêm tổng summaries
            Me.Ketoantienmat_thongtinthueIUltraGrid.setSummaries("doanhthu")
            Me.Ketoantienmat_thongtinthueIUltraGrid.setSummaries("thue")
            Me.Ketoantienmat_thongtinthueIUltraGrid.setSummaries("tongcong")
            Me.Ketoantienmat_thongtinthueIUltraGrid.setTimKiemTrenCotUltraGrid()

            Me.KetoantienmatIUltraGrid_ThongTin.setTimKiemTheoShift()
            Me.Ketoantienmat_thongtinthueIUltraGrid.setTimKiemTheoShift()
            Me.setReadOnly(True)
            'Me.DmkhachhangBindingSource.Filter = "manhomkh = 'KH'"
            'Me.KetoantienmatIUltraGrid_DanhSach.setGroupBy("ma")
            Me.Cursor = Cursors.Default
            'load.Close()
            Me.isLoad = False
        End If
    End Sub
    Private Sub KeToanTienMat1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    'để cho lưới readonly
    Private Sub setReadOnly(ByVal isTrue As Boolean)
        Me.KetoantienmatIUltraGrid_ThongTin.setReadonly(isTrue)
        Me.Ketoantienmat_thongtinchinhIUltraGrid.setReadonly(isTrue)
        Me.Ketoantienmat_thongtinthueIUltraGrid.setReadonly(isTrue)
        Me.KetoantienmatIUltraGrid_DanhSach.setReadonly(isTrue)
    End Sub
    Private Function getTaoMoi()
        Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("ma", getMa)
        If (Me.KetoantienmatIUltraGrid_ThongTin.getTaoMoi()) Then
            Me.setReadOnly(False)
            Me.state = 1
            Return True
        Else
            Return False
        End If
    End Function
    Private Sub btnTaoMoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTaoMoi.Click
        getTaoMoi()
    End Sub
    Private Function getLuu()
        Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("nguyente").Value = Me.Ketoantienmat_thongtinchinhIUltraGrid.Rows.SummaryValues("thanhtiennguyente").Value
        Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("quidoi").Value = Me.Ketoantienmat_thongtinchinhIUltraGrid.Rows.SummaryValues("thanhtienvnd").Value
        If Me.KetoantienmatIUltraGrid_ThongTin.getLuu() Or Me.Ketoantienmat_thongtinchinhIUltraGrid.getLuuNgam() Or Me.Ketoantienmat_thongtinthueIUltraGrid.getLuuNgam() Then
            Me.setReadOnly(True)
            Me.state = 0
            Return True
        Else
            Return False
        End If
    End Function
    Private Sub btnLuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLuu.Click
        getLuu()
    End Sub
    Private Function getSua()
        If KetoantienmatIUltraGrid_ThongTin.getSua() And Me.Ketoantienmat_thongtinchinhIUltraGrid.getSua And Me.Ketoantienmat_thongtinthueIUltraGrid.getSua Then
            Me.setReadOnly(False)
            Me.state = 2
            Return True
        Else
            Return False
        End If
    End Function
    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        getSua()
    End Sub
    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        KetoantienmatIUltraGrid_ThongTin.getXoa()
    End Sub

    Private Sub btnLamTuoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLamTuoi.Click
        Me.KetoantienmatIUltraGrid_ThongTin.getRefresh()
    End Sub

    Private Sub btnIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIn.Click
        'Me.Ketoantienmat_thongtinthueIUltraGrid.DisplayLayout.Bands(0).AddNew()
        'Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("ma").Value = Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("ma").Value
        ''Me.Ketoantienmat_thongtinthueIUltraGrid.Rows().Move(row, 0)
        ''Ketoantienmat_thongtinthueIUltraGrid.setGroupBy()
    End Sub
    Private Function getThoat()
        If Me.KetoantienmatIUltraGrid_ThongTin.getCoThayDoiDuLieuKhong Or Me.Ketoantienmat_thongtinchinhIUltraGrid.getCoThayDoiDuLieuKhong Or Me.Ketoantienmat_thongtinthueIUltraGrid.getCoThayDoiDuLieuKhong Then
            If KetoantienmatIUltraGrid_ThongTin.getLuu Then
                Ketoantienmat_thongtinchinhIUltraGrid.getLuuNgam()
                Ketoantienmat_thongtinthueIUltraGrid.getLuuNgam()
            End If
            Return True
        Else
            Me.Dispose()
            Me.Close()
            Return True
        End If
    End Function
    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        getThoat()
    End Sub
    'mã tự động của phiếu
    Private Function getMa() As String
        'Try
        '    Dim ma As String = Me.HttientoTableAdapter.getMaMuaHangTrongNuoc(New Date(2012, 4, 1), New Date(2012, 4, 30))
        '    Return ma
        'Catch ex As Exception
        '    Return Today.Year & Today.Month & Today.Day
        'End Try
        Return ""
    End Function

    Private Sub KetoantienmatIUltraGrid_ThongTin_AfterCellListCloseUp(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles KetoantienmatIUltraGrid_ThongTin.AfterCellListCloseUp
        Try
            If KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("nghiepvu").IsActiveCell Then
                Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("taikhoanno", Me.DmnghiepvuIUltraDropDown.ActiveRow.Cells("taikhoanno").Value)
                Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("taikhoanco", Me.DmnghiepvuIUltraDropDown.ActiveRow.Cells("taikhoanco").Value)
                'Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("taikhoanvat", Me.DmnghiepvuIUltraDropDown.ActiveRow.Cells("taikhoanvat").Value)
            End If
            If KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("nhacungcap").IsActiveCell Then
                Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("diachi").Value = Me.DmkhachhangIUltraDropDown.ActiveRow.Cells("diachi").Value
                'Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("diachi", Me.DmkhachhangIUltraDropDown.ActiveRow.Cells("diachi").Value)
                'Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("masothue", Me.DmkhachhangIUltraDropDown.ActiveRow.Cells("masothue").Value)
            End If
            If KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("bophan").IsActiveCell Then
                Me.Ketoantienmat_thongtinchinhIUltraGrid.setMacDinh("phongban", Me.DmphongbanIUltraDropDown.ActiveRow.Cells("ma").Value)
            End If
        Catch ex As Exception
            ' MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub KetoantienmatIUltraGrid_ThongTin_BeforeCellDeactivate(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles KetoantienmatIUltraGrid_ThongTin.BeforeCellDeactivate
        If Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("nghiepvu").IsActiveCell Then
            Me.KetoantienmatIUltraGrid_ThongTin.getLuuNgam()
        End If
        If Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("trangthai").IsActiveCell And (state = 2 Or state = 1) Then
            Me.KetoantienmatIUltraGrid_ThongTin.getLuuNgam()
            Me.KetoantienmatIUltraGrid_ThongTin.setFocusCellUltraGrid(Me.Ketoantienmat_thongtinchinhIUltraGrid)
        End If
    End Sub
    Private Sub tinhDong_ThongTinChinh()
        If Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("dongianguyente").IsActiveCell Then
            Try
                Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("thanhtiennguyente").Value = CDec(Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("soluong").Value) * CDec(Me.Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("dongianguyente").Value)
            Catch ex As Exception
                Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("thanhtiennguyente").Value = 0
            End Try
        End If
        If Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("dongiavnd").IsActiveCell Then
            Try
                Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("thanhtienvnd").Value = CDec(Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("soluong").Value) * CDec(Me.Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("dongiavnd").Value)
            Catch ex As Exception
                Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("thanhtienvnd").Value = 0
            End Try
        End If
    End Sub

    Private Sub Ketoantienmat_thongtinchinhIUltraGrid_AfterCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles Ketoantienmat_thongtinchinhIUltraGrid.AfterCellUpdate
        tinhDong_ThongTinChinh()
    End Sub

    Private Sub Ketoantienmat_thongtinchinhIUltraGrid_DoubleClickCell(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.DoubleClickCellEventArgs) Handles Ketoantienmat_thongtinchinhIUltraGrid.DoubleClickCell
        If Me.Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Index = 0 And (state = 2 Or state = 1) Then
            Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("donvi").Value = Me.Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("donvi").Value
        End If
    End Sub

    Private Sub Ketoantienmat_thongtinchinhIUltraGrid_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Ketoantienmat_thongtinchinhIUltraGrid.MouseEnter
        Me.loadDuLieu()
    End Sub
    Private Sub tinhDong_ThongTinThue() 'tính doanh thu nếu gõ %thue
        If Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("phantramthue").IsActiveCell Then
            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("thue").Value = CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("tongcong").Value) * CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("phantramthue").Value) / 100
            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("doanhthu").Value = CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("tongcong").Value) - CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("thue").Value)
        End If
        If Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("thue").IsActiveCell Then
            Dim thue As Decimal = CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("thue").Value)
            Dim tongcong As Decimal = CDec(Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("tongcong").Value)
            Dim phantramthue As Integer = Math.Round(thue / tongcong * 100, 0)
            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("doanhthu").Value = tongcong - thue
            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("phantramthue").Value = phantramthue
        End If
    End Sub
    Private Sub Ketoantienmat_thongtinchinhIUltraGrid_SummaryValueChanged(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.SummaryValueChangedEventArgs) Handles Ketoantienmat_thongtinchinhIUltraGrid.SummaryValueChanged
        'Try
        '    Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("nguyente").Value = Me.Ketoantienmat_thongtinchinhIUltraGrid.Rows.SummaryValues("nguyente").Value
        '    Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("tienvnd").Value = Me.Ketoantienmat_thongtinchinhIUltraGrid.Rows.SummaryValues("tienvnd").Value
        'Catch ex As Exception

        'End Try
    End Sub

    Private Sub ultraTabChiTiet_SelectedTabChanged(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs) Handles ultraTabChiTiet.SelectedTabChanged
        'Dim groupByRow As UltraGridGroupByRow
        'If Me.ultraTabChiTiet.SelectedTab Is ultraTabChiTiet.Tabs("thongtinthue") Then
        '    Me.Ketoantienmat_thongtinchinhIUltraGrid.setGroupBy("sohoadon")
        '    If Ketoantienmat_thongtinthueIUltraGrid.getCoThayDoiDuLieuKhong Then
        '        If MessageBox.Show("Bạn có muốn lấy dữ liệu sang thuế tự động hay không ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
        '            For index = 0 To Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.ParentCollection.Count - 1
        '                Try
        '                    Me.Ketoantienmat_thongtinthueIUltraGrid.DisplayLayout.Bands(0).AddNew()
        '                    groupByRow = Ketoantienmat_thongtinchinhIUltraGrid.Rows(index)
        '                    Dim sum As Double = groupByRow.Rows.SummaryValues("tienvnd").Value
        '                    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("ma").Value = Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("ma").Value
        '                    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("donvi").Value = groupByRow.Rows(0).Cells("donvi").Value
        '                    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("sohoadon").Value = groupByRow.Rows(0).Cells("sohoadon").Value
        '                    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("ngayhoadon").Value = groupByRow.Rows(0).Cells("ngay").Value
        '                    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("doanhthu").Value = sum
        '                    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("phantramthue").Value = 0
        '                    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("thue").Value = 0
        '                    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("tongcong").Value = sum
        '                Catch ex As Exception

        '                End Try
        '            Next
        '        End If

        'Me.Ketoantienmat_thongtinchinhIUltraGrid.setGroupBy("sohoadon")
        'MessageBox.Show(Me.Ketoantienmat_thongtinchinhIUltraGrid.Rows.SummaryValues.Item(0).Value)

        'For index = 0 To 1
        '    Me.Ketoantienmat_thongtinthueIUltraGrid.DisplayLayout.Bands(0).AddNew()
        '    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("ma").Value = Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("ma").Value
        '    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("doanhthu").Value = 0
        '    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("phantramthue").Value = 0
        '    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("thue").Value = 0
        '    Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("tongcong").Value = 0
        'Next

        'Dim groupByRow As UltraGridGroupByRow = Ketoantienmat_thongtinchinhIUltraGrid.Rows(0)
        'Dim groupByRow1 As UltraGridGroupByRow = Ketoantienmat_thongtinchinhIUltraGrid.Rows(1)
        'MessageBox.Show(groupByRow.Rows.SummaryValues(2).Value)
        'MessageBox.Show(groupByRow1.Rows.SummaryValues(2).Value)
        'MessageBox.Show(Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.ParentCollection.Count)
        '    End If
        'End If
        'If Me.ultraTabChiTiet.SelectedTab Is ultraTabChiTiet.Tabs("thongtinchinh") Then
        '    'Me.Ketoantienmat_thongtinchinhIUltraGrid.DisplayLayout.ClearGroupByColumns()
        '    ''Ketoantienmat_thongtinchinhIUltraGrid.DisplayLayout.ResetGroupByBox()
        '    'Me.Ketoantienmat_thongtinchinhIUltraGrid.DisplayLayout.ViewStyleBand = 
        '    Ketoantienmat_thongtinchinhIUltraGrid.setClearGroupBy()
        'End If
    End Sub

    Private Sub DmkhachhangIUltraGrid_DoubleClickCell(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.DoubleClickCellEventArgs) Handles DmkhachhangIUltraGrid.DoubleClickCell
        Try
            Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("donvi").Value = DmkhachhangIUltraGrid.ActiveRow.Cells("ma").Value
        Catch ex As Exception
        End Try
    End Sub

    Private Sub DmkhachhangIUltraGrid1_DoubleClickCell(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.DoubleClickCellEventArgs) Handles DmkhachhangIUltraGrid1.DoubleClickCell
        Try
            Me.Ketoantienmat_thongtinchinhIUltraGrid.ActiveRow.Cells("donvi").Value = DmkhachhangIUltraGrid1.ActiveRow.Cells("ma").Value
        Catch ex As Exception
        End Try
    End Sub

    Private Sub KetoantienmatIUltraGrid_ThongTin_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles KetoantienmatIUltraGrid_ThongTin.MouseEnter
        Me.loadDuLieu()
    End Sub

    Private Sub KetoantienmatIUltraGrid_DanhSach_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles KetoantienmatIUltraGrid_DanhSach.MouseEnter
        Me.loadDuLieu()
    End Sub

    Private Sub Ketoantienmat_thongtinthueIUltraGrid_AfterCellListCloseUp(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles Ketoantienmat_thongtinthueIUltraGrid.AfterCellListCloseUp
        If Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("donvi").IsActiveCell Then
            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("diachi").Value = Me.DmkhachhangIUltraDropDown.ActiveRow.Cells("diachi").Value
            Ketoantienmat_thongtinthueIUltraGrid.ActiveRow.Cells("masothue").Value = Me.DmkhachhangIUltraDropDown.ActiveRow.Cells("masothue").Value
        End If
    End Sub

    Private Sub Ketoantienmat_thongtinthueIUltraGrid_AfterCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles Ketoantienmat_thongtinthueIUltraGrid.AfterCellUpdate
        tinhDong_ThongTinThue()
    End Sub

    Private Sub Ketoantienmat_thongtinthueIUltraGrid_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Ketoantienmat_thongtinthueIUltraGrid.MouseEnter
        Me.loadDuLieu()
    End Sub

    Private Sub Ketoantienmat_thongtinchinhIUltraGrid_TimKiem_ClickCell(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.ClickCellEventArgs) Handles Ketoantienmat_thongtinchinhIUltraGrid_TimKiem.ClickCell
        Try
            Me.MuahangtrongnuocBindingSource.Position = Me.MuahangtrongnuocBindingSource.Find("ma", Me.Ketoantienmat_thongtinchinhIUltraGrid_TimKiem.ActiveRow.Cells("ma").Value.ToString)
        Catch ex As Exception

        End Try
    End Sub
    Private Sub Ketoantienmat_thongtinthueIUltraGrid_TimKiem_ClickCell(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.ClickCellEventArgs) Handles Ketoantienmat_thongtinthueIUltraGrid_TimKiem.ClickCell
        Try
            Try
                Me.MuahangtrongnuocBindingSource.Position = Me.MuahangtrongnuocBindingSource.Find("ma", Me.Ketoantienmat_thongtinthueIUltraGrid_TimKiem.ActiveRow.Cells("ma").Value.ToString)
            Catch ex As Exception

            End Try
        Catch ex As Exception

        End Try
    End Sub

End Class